package com.wondertek.poms.core.service.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ArrayUtil;
import com.wondertek.poms.common.service.impl.ServiceImpl;
import com.wondertek.poms.common.utils.StringUtil;
import com.wondertek.poms.common.vo.ResultBean;
import com.wondertek.poms.core.config.MsgConfig;
import com.wondertek.poms.core.service.IContentFeeService;
import com.wondertek.poms.core.service.IPrdContService;
import com.wondertek.poms.core.service.IProductService;
import com.wondertek.poms.core.service.ISellingPriceLogService;
import com.wondertek.poms.dao.bo.ContentFeeBo;
import com.wondertek.poms.dao.po.*;
import com.wondertek.poms.dao.pojo.ContentFeePojo;
import com.wondertek.poms.dao.pojo.PrdContSelPojo;
import com.wondertek.poms.dao.repo.*;
import com.wondertek.poms.dao.vo.PrdContVo;
import com.wondertek.poms.dao.vo.ProductChargeVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author chenjijiang
 * @description
 */
@Service
@Slf4j
@Scope("prototype")
public class ContentFeeServiceImpl extends ServiceImpl<ContentFee, Long> implements IContentFeeService {
	@Autowired
	private IContentFeeDao contentFeeDao;
	@Autowired
	private IProductService productService;
	@Autowired
	private IPrdContDao prdContDao;
	@Autowired
	private IContentDao contentDao;
	@Autowired
	private IChannelPackageDao channelPackageDao;
	@Autowired
	private IProductGroupDao productGroupDao;
	@Autowired
	private IEquityNodeDao equityNodeDao;
	@Autowired
	private IPrdInfoDao prdInfoDao;
	@Autowired
	private ISellingPriceLogDao sellingPriceLogDao;
	@Autowired
	private IPrdContService prdContService;
	@Autowired
	private ISellingPriceLogService sellingPriceLogService;
	@PersistenceContext
	public EntityManager entityManager;
	@Autowired
	private MsgConfig msgConfig;
	@Override
	public ContentFee deleteLogic(Long id) {
		return null;
	}

	@Override
	public ContentFee merge(ContentFee model) {
		return null;
	}

	@Override
	public List<ContentFee> findAllByPomsId(List<Long> ids, String nowTime) {
		return contentFeeDao.findAllByPomsId(ids, nowTime);
	}

	@Override
	public List<ContentFee> queryContentFee(String infoId, String prdContId) {
		List<ContentFee> list = new ArrayList<ContentFee>();
		StringBuffer sql = new StringBuffer(" ");
		sql.append(" select fee.TYPE,fee.POMS_ID,fee.PRICE,fee.ORDER_FLAG,fee.DISCOUNT,fee.SALE_CATEGORY, fee.CHANNEL_PACKAGE_ID " +
				"from CONTENT_FEE  fee where fee.POMS_ID in (" + infoId + "," + prdContId + ") and fee.START_TIME <= :startTime  and :endTime <= fee.END_TIME ");
		Query nativeQuery = entityManager.createNativeQuery(sql.toString());
		nativeQuery.setParameter("startTime", new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
		nativeQuery.setParameter("endTime", new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
		List<Object[]> resultList = nativeQuery.getResultList();
		for (Object[] obj : resultList) {
			ContentFee fee = new ContentFee();
			fee.setType(StringUtil.nullToInteger(obj[0]));
			fee.setPomsId(StringUtil.nullToLong(obj[1]));
			fee.setPrice(StringUtil.null2Str(obj[2]));
			fee.setOrderFlag(StringUtil.null2Str(obj[3]));
			fee.setDiscount(StringUtil.null2Str(obj[4]));
			fee.setSaleCategory(StringUtil.nullToInteger(obj[5]));
			fee.setChannelPackageId(obj[6] == null ? null : StringUtil.nullToLong(obj[6]));
			list.add(fee);
		}
		return list;
	}

	@Override
	public List<ProductChargeVo> findByPomsIdAndType(String pomsIdS,int type) {
		List<ContentFee> list = new ArrayList<ContentFee>();
		List<ProductChargeVo> list1 = new ArrayList<ProductChargeVo>();
		String[] ids = pomsIdS.split(",");
		for (String id : ids) {
			list =contentFeeDao.findByPomsIdAndType(Long.parseLong(id),type);
		}
		if (list.size() > 0) {
			for (ContentFee fee : list) {
				Product product = null;
				if (!StringUtil.isNullStr(fee.getSaleProductId())) {
					product = productService.getByProductId(fee.getSaleProductId());
				}
				if (!StringUtil.isNullStr(fee.getEquityId())) {
					ProductChargeVo productCharge = new ProductChargeVo();
					productCharge.setId(StringUtil.nullToString(fee.getId()));
					productCharge.setPrdContId(StringUtil.nullToString(fee.getPomsId()));
					productCharge.setEquityId(fee.getEquityId());
					EquityNode equityNode = equityNodeDao.findEquityNodeByEquityNodeId(fee.getEquityId());
					productCharge.setEquityCode(equityNode.getEquityNodeId());
					ProductGroup productGroup = productGroupDao.getOne(equityNode.getGroupId());
					productCharge.setGroupName(productGroup.getGroupName());
					productCharge.setStartTime(fee.getStartTime());
					productCharge.setEndTime(fee.getEndTime());
					list1.add(productCharge);
				} else if (!StringUtil.isNullStr(fee.getDiscount())) {
					ProductChargeVo productCharge = new ProductChargeVo();
					product=product==null?new Product():product;
					productCharge.setName(product.getName());
					productCharge.setPrice(product.getPrice());
					productCharge.setPrdContId(StringUtil.nullToString(fee.getPomsId()));
					productCharge.setChargeProductId(product.getProductID());
					productCharge.setChargeMode(product.getChargeMode());
					productCharge.setStartTime(fee.getStartTime());
					productCharge.setEndTime(fee.getEndTime());
					productCharge.setSalCategory(fee.getSaleCategory());
					productCharge.setId(fee.getId().toString());
					productCharge.setDiscount(fee.getDiscount());
					productCharge.setChannelPackageId(StringUtil.nullToString(fee.getChannelPackageId()));
					if(fee.getChannelPackageId()!=null){
						ChannelPackage ChannelPackage=channelPackageDao.getOne(fee.getChannelPackageId());
						productCharge.setChannelPackageName(ChannelPackage.getName());
					}
					productCharge.setClientType(StringUtil.nullToString(fee.getClientType()));
					list1.add(productCharge);
				} else {
					ProductChargeVo productCharge = new ProductChargeVo();
					productCharge.setPrdContId(StringUtil.nullToString(fee.getPomsId()));
					productCharge.setId(fee.getId().toString());
					productCharge.setChargeProductId(product.getProductID());
					productCharge.setChargeMode(product.getChargeMode());
					productCharge.setPrice(fee.getPrice());
					productCharge.setName(product.getName());
					productCharge.setStartTime(fee.getStartTime());
					productCharge.setEndTime(fee.getEndTime());
					list1.add(productCharge);
				}
			}
		}
		return list1;
	}

	List<ContentFee> getListByObjs(List<Object[]> objs){
		List<ContentFee> list = new ArrayList<ContentFee>();
		if (objs != null && objs.size() > 0) {
			for (Object[] obj : objs) {
				ContentFee fee  = new ContentFee();
				if (obj[0]!=null) {
					fee.setSaleCategory(StringUtil.nullToInteger(obj[0]));
				}
				if (obj[1]!=null) {
					fee.setStartTime(StringUtil.null2Str(obj[1]));
				}
				if (obj[2]!=null) {
					fee.setEndTime(StringUtil.null2Str(obj[2]));
				}
				if (obj[3]!=null) {
					fee.setDiscount(StringUtil.null2Str(obj[3]));
				}
				if (obj[4]!=null) {
					fee.setChannelPackageId(StringUtil.nullToLong(obj[4]));
				}
				if (obj[5]!=null) {
					fee.setClientType(StringUtil.nullToInteger(obj[5]));
				}
				if (obj[6]!=null) {
					fee.setPrice(StringUtil.null2Str(obj[6]));
				}
				if (obj[7]!=null) {
					fee.setPriceType(StringUtil.null2Str(obj[7]));
				}
				if (obj[8]!=null) {
					fee.setSaleProductId(StringUtil.null2Str(obj[8]));
				}
				list.add(fee);
			}
		}
		return list;
	}

	/** 生产对应sql
	 *@author gaozhengxing gaozhenghang@wondertek.com.cn
	 *@date 2021/1/8 17:41
	 *@param count true 查数量接口
	 *@param contentFeeBo 参数
	 *@return  sql*/
	String createSqlForContentFeeBo(boolean count,ContentFeeBo contentFeeBo){
		StringBuilder hql = new StringBuilder();
		hql.append("select ");
		if(count){
			hql.append("count(0) ");
		}else{
			hql.append(" c.sale_category,c.start_time,c.end_time,c.discount," +
					"c.channel_package_id,c.client_type,c.price,c.price_type,c.SALE_PRODUCT_ID  ");
		}
		hql.append(" from content_fee c where 1 =1 ");
		if(!StringUtil.isNullStr(contentFeeBo.getType())){
			hql.append(" and c.type = "+contentFeeBo.getType());
		}
		if(!StringUtil.isNullStr(contentFeeBo.getPomsId())){
			hql.append(" and c.POMS_ID = "+contentFeeBo.getPomsId());
		}
		if(!StringUtil.isNullStr(contentFeeBo.getHasCltType())){
			hql.append(" and c.CLIENT_TYPE is not null ");
		}else if(!StringUtil.isNullStr(contentFeeBo.getHasChannel())) {
			hql.append(" and c.CHANNEL_PACKAGE_ID is not null ");
		}
		if(!StringUtil.isNullStr(contentFeeBo.getChannelPackageId())){
			hql.append(" and c.CHANNEL_PACKAGE_ID = "+contentFeeBo.getChannelPackageId());
		}
		if("1".equals(contentFeeBo.getSign())){
			hql.append(" and c.channelPackageId is null ");
			hql.append(" and c.CLIENT_TYPE is null ");
		}
		if("2".equals(contentFeeBo.getSign())){
			hql.append(" and c.CHANNEL_PACKAGE_ID is null ");
		}
		if(!StringUtil.isNullStr(contentFeeBo.getCategory())){
			hql.append(" and c.SALE_CATEGORY = "+contentFeeBo.getCategory());
		}
		if(!StringUtil.isNullStr(contentFeeBo.getClientType())){
			hql.append(" and c.CLIENT_TYPE = "+contentFeeBo.getClientType());
		}
		System.out.println(hql.toString());
		return hql.toString();
	}


	@Override
	public List<ContentFee> getList(ContentFeeBo contentFeeBo) {
		Query nativeQuery = entityManager.createNativeQuery(createSqlForContentFeeBo(false,contentFeeBo));
		List<Object[]> resultList = nativeQuery.getResultList();
		return getListByObjs(resultList);
	}
	@Override
	public int getCount(ContentFeeBo contentFeeBo) {
		Object obj =entityManager.createNativeQuery(createSqlForContentFeeBo(true,contentFeeBo)).getSingleResult();
		return Convert.toInt(obj);
	}

	@Override
	public ResultBean prdSalDel(String contentFeeIds){
		String[] ids = contentFeeIds.split(",");
		try {
			for (String key : ids) {
				ContentFee fee = contentFeeDao.getOne(Long.valueOf(key));
				Long prdContId = fee.getPomsId();
				PrdCont prd = prdContDao.findByPrdContId(prdContId);
				PrdInfo prdInfo = prdInfoDao.getOne(prd.getPrdInfoId());
				if(prdInfo!=null){
					if ((prdInfo.getAutoVomsPublish() == 1 && prd.getPublishNoVOMSStatus() == null)
							|| "22".equals(prd.getPublishNoVOMSStatus()) ) {
						prdContDao.updatePublishNoVOMSStatus(PrdCont.PUBON_STATUS_NOT,prd.getPrdContId());
						System.out.println(13);
					}
				}
				// 记录日志
				sellingPriceLogService.saveByPragma(fee,prd,null,null,null,null,"1",null);
				deleteById(Long.valueOf(key));
			}
		}catch (Exception e){
			log.error("ContentFeeServiceImpl#prdSalDel 执行错误:"+e.toString());
			ResultBean.ok(e.toString());
		}
		return ResultBean.ok();
	}

	@Override
	public List<ContentFee> findByPomsIdAndType(Long pomsId,Integer type) {
		List<ContentFee> list = new ArrayList<ContentFee>();
		StringBuffer sqlQuery = new StringBuffer();
		sqlQuery.append(" select c.sale_category,				");
		sqlQuery.append("        c.start_time,                 ");
		sqlQuery.append("        c.end_time,                   ");
		sqlQuery.append("        c.discount,                   ");
		sqlQuery.append("        c.channel_package_id,         ");
		sqlQuery.append("        c.client_type,         		");
		sqlQuery.append("        c.price,                      ");
		sqlQuery.append("        c.price_type,                 ");
		sqlQuery.append("        listagg(c.sale_product_id,',') within GROUP (order by c.sale_product_id)  ");
		sqlQuery.append("   from content_fee cf                 ");
		sqlQuery.append("  where c.type = :type                ");
		sqlQuery.append("    and c.poms_id = :pomsId       	");
		sqlQuery.append("  group by c.sale_category,           ");
		sqlQuery.append("           c.start_time,              ");
		sqlQuery.append("           c.end_time,                ");
		sqlQuery.append("           c.discount,                ");
		sqlQuery.append("           c.channel_package_id,		");
		sqlQuery.append("           c.client_type,				");
		sqlQuery.append("           c.price,			        ");
		sqlQuery.append("           c.price_type			    ");
		Query nativeQuery = entityManager.createNativeQuery(sqlQuery.toString());
		nativeQuery.setParameter("type", type);
		nativeQuery.setParameter("pomsId", pomsId);
		List<Object[]> resultList = nativeQuery.getResultList();
		return getListByObjs(resultList);
	}

	@Override
	public List<ContentFee> findByTypeAndPomsId(Integer type, Long pomsId) {
		List<ContentFee> list = new ArrayList<ContentFee>();
		StringBuffer sqlQuery = new StringBuffer();
		sqlQuery.append(" select cf.sale_category,				");
		sqlQuery.append("        cf.start_time,                 ");
		sqlQuery.append("        cf.end_time,                   ");
		sqlQuery.append("        cf.discount,                   ");
		sqlQuery.append("        cf.channel_package_id,         ");
		sqlQuery.append("        cf.client_type,         		");
		sqlQuery.append("        cf.price,                      ");
		sqlQuery.append("        cf.price_type,                 ");
		sqlQuery.append("        listagg(cf.sale_product_id,',') within GROUP (order by cf.sale_product_id)  ");
		sqlQuery.append("   from content_fee cf                 ");
		sqlQuery.append("  where cf.type = :type                ");
		sqlQuery.append("    and cf.poms_id = :pomsId       	");
		sqlQuery.append("  group by cf.sale_category,           ");
		sqlQuery.append("           cf.start_time,              ");
		sqlQuery.append("           cf.end_time,                ");
		sqlQuery.append("           cf.discount,                ");
		sqlQuery.append("           cf.channel_package_id,		");
		sqlQuery.append("           cf.client_type,				");
		sqlQuery.append("           cf.price,			        ");
		sqlQuery.append("           cf.price_type			    ");
		Query nativeQuery = entityManager.createNativeQuery(sqlQuery.toString());
		nativeQuery.setParameter("type", type);
		nativeQuery.setParameter("pomsId", pomsId);
		List<Object[]> resultList = nativeQuery.getResultList();
		if (resultList != null && resultList.size() > 0) {
			ContentFee fee = null;
			for (Object[] obj : resultList) {
				fee = new ContentFee();
				if (!StringUtil.isNullStr(obj[0])) {
					fee.setSaleCategory(StringUtil.nullToInteger(obj[0]));
				}
				if (!StringUtil.isNullStr(obj[1])) {
					fee.setStartTime(StringUtil.null2Str(obj[1]));
				}
				if (!StringUtil.isNullStr(obj[2])) {
					fee.setEndTime(StringUtil.null2Str(obj[2]));
				}
				if (!StringUtil.isNullStr(obj[3])) {
					fee.setDiscount(StringUtil.null2Str(obj[3]));
				}
				if (!StringUtil.isNullStr(obj[4])) {
					fee.setChannelPackageId(StringUtil.nullToLong(obj[4]));
				}
				if (!StringUtil.isNullStr(obj[5])) {
					fee.setClientType(StringUtil.nullToInteger(obj[5]));
				}
				if (!StringUtil.isNullStr(obj[6])) {
					fee.setPrice(StringUtil.null2Str(obj[6]));
				}
				if (!StringUtil.isNullStr(obj[7])) {
					fee.setPriceType(StringUtil.null2Str(obj[7]));
				}
				if (!StringUtil.isNullStr(obj[8])) {
					fee.setSaleProductId(StringUtil.null2Str(obj[8]));
				}
				list.add(fee);
			}
		}
		return list;
	}

	@Override
	public ResultBean  prdSalSave(ContentFeePojo contentFeePojo) {
		String productId = contentFeePojo.getProductIds();
		String category = contentFeePojo.getCategory();
		String startTime = contentFeePojo.getStartTime();
		String endTime = contentFeePojo.getEndTime();
		String disCount = contentFeePojo.getDisCount();
		String prdContIds = contentFeePojo.getPrdContIds();
		String channelInfoPackage = contentFeePojo.getChannelPackageId();
		String clientTypes = contentFeePojo.getClientTypes();
		String sellingPriceProductId = contentFeePojo.getPrice();
		String equityIds = contentFeePojo.getEquityIds();

		if(StringUtils.isNotBlank(sellingPriceProductId)){
			if(StringUtils.isBlank(startTime) || StringUtils.isBlank(endTime)){
				return ResultBean.error("选择售价名称后,必须选择开始时间和结束时间");
			}
			if(StringUtils.isNotBlank(productId) || StringUtils.isNotBlank(category) || StringUtils.isNotBlank(disCount)
					||StringUtils.isNotBlank(channelInfoPackage) || StringUtils.isNotBlank(clientTypes) || StringUtils.isNotBlank(equityIds)){
				return ResultBean.error("选择售价名称后,只能选择选择开始时间和结束时间");
			}
		}
		ContentFeeBo contentFeeBo=new ContentFeeBo();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String start = "";
		String end = "";
		try {
			Date startDate = sdf.parse(startTime.replace("T", " "));
			Date endDate = sdf.parse(endTime.replace("T", " "));
			start = sdf.format(startDate);
			end = sdf.format(endDate);
		} catch (ParseException e1) {
			log.info(e1.toString());
			return ResultBean.error(msgConfig.getParseException());
		}

		// channelInfoPackage 与 clientType 互斥
		if (!StringUtil.isNullStr(channelInfoPackage)
				&& !StringUtil.isNullStr(clientTypes)) {
			return ResultBean.error(msgConfig.getChannelPkgClientOnlyOne());
		}
		if (StringUtil.isNullStr(prdContIds)) {
			return ResultBean.error(msgConfig.getChannelPkgPrdContIdsNotNull());
		}

		String[] ids = prdContIds.split(",");
		try {
			for (String id : ids) {
				int count=0;
				contentFeeBo.setType("2");
				contentFeeBo.setPomsId(id);
				if (!StringUtil.isNullStr(channelInfoPackage) && StringUtil.isNullStr(clientTypes)) {
					System.out.println(1);
					contentFeeBo.setHasCltType("hasCltType");
					count=getCount(contentFeeBo);
					contentFeeBo.setHasCltType(null);
					if (count> 0) {
						System.out.println(2);
						return ResultBean.error(msgConfig.getPrdContConfigCltTypeNoChannel()+"对应id:"+id);
					}
				} else if (StringUtil.isNullStr(channelInfoPackage) && !StringUtil.isNullStr(clientTypes)) {
					System.out.println(3);
					contentFeeBo.setHasChannel("hasChannel");
					count=getCount(contentFeeBo);
					contentFeeBo.setHasChannel(null);
					if (count > 0) {
						System.out.println(4);
						return ResultBean.error(msgConfig.getPrdContConfigChannelNoCltType()+"对应id:"+id);
					}
				}
				// 确保时间没有冲突
				if (!StringUtil.isNullStr(start) && !StringUtil.isNullStr(end)) {
					System.out.println(5);
					List<ContentFee> list = getList(contentFeeBo);
					try {
						long st = sdf.parse(start).getTime();
						long ed = sdf.parse(end).getTime();
						for (ContentFee fee : list) {
							if (fee.getEndTime() != null
									&& fee.getStartTime() != null) {
								long st1 = sdf.parse(fee.getStartTime())
										.getTime();
								long ed1 = sdf.parse(fee.getEndTime())
										.getTime();
								if (!(st > ed1 || ed < st1)) {
									return ResultBean.error(msgConfig.getSellingPriceTimeConflict()+"对应节目id:"+id);
								}
							}
						}
					} catch (ParseException e1) {
						log.info(e1.toString());
						return ResultBean.error(msgConfig.getParseException());
					}
				}
				// 添加记录条件
				System.out.println(6);
				PrdContSelPojo prdContSelPojo=new PrdContSelPojo();
				prdContSelPojo.setPrdContId(Long.parseLong(id));
				List<PrdContVo>  list=prdContService.findPrdContVoList(prdContSelPojo,1,1,null,null);
				System.out.println(7);
				PrdContVo prdContVo=new PrdContVo();
				if(ArrayUtil.isAllNotEmpty(list)){
					prdContVo=list.get(0);
				}
				String name = prdContVo.getContentName();
				String contentId = prdContVo.getContentId().toString();
				String prdInfoId = prdContVo.getPrdInfoId();
				if (!StringUtil.isNullStr(productId)) {
					String[] productIDs = productId.split(",");
					for (String productID : productIDs) {
						boolean beSaved = false;
						System.out.println(8);
						List<Product> productList = productService.findAllByProductId(productID);
						Product product=new Product();
						if(productList!=null && productList.size()>0){
							product=productList.get(0);
						}
						ContentFee fee=new ContentFee();
						fee.setPomsId(Long.valueOf(id));
						fee.setSaleProductId(productID);
						fee.setSaleCategory(Integer.parseInt(category));
						fee.setStartTime(start);
						fee.setEndTime(end);
						fee.setType(2);
						fee.setDiscount(disCount);
						fee.setOrderFlag(product.getChargeMode());
						fee.setPrice(product.getPrice());
						if (StringUtil.isNullStr(channelInfoPackage)&& StringUtil.isNullStr(clientTypes)) {
							contentFeeDao.save(fee);
							beSaved = true;
						} else if (!StringUtil.isNullStr(channelInfoPackage)
								&& StringUtil.isNullStr(clientTypes)) {
							String[] chanelPkgIDs = channelInfoPackage
									.split(",");
							for (String chanelPkgID : chanelPkgIDs) {
								fee.setChannelPackageId(Long.valueOf(chanelPkgID));
								contentFeeDao.save(fee);
								fee.setChannelPackageId(null);
							}
							beSaved = true;
						} else if (StringUtil.isNullStr(channelInfoPackage)
								&& !StringUtil.isNullStr(clientTypes)) {
							String[] cltType = clientTypes.split(",");
							for (String clientType : cltType) {
								fee.setClientType(StringUtil.nullToInteger(clientType));
								contentFeeDao.save(fee);
								System.out.println(9);
								fee.setClientType(null);
							}
							beSaved = true;
						}
						if (beSaved) {
							String prdPrice = product.getPrice();
							SellingPriceLog sellingPriceLog=new SellingPriceLog();
							SellingPriceLog.putTimeAndUser(sellingPriceLog);
							sellingPriceLog.setName(name);
							sellingPriceLog.setContentId(contentId);
							sellingPriceLog.setPrice(prdPrice);
							sellingPriceLog.setPrdInfoId(id);
							sellingPriceLog.setProductName(product.getName());
							sellingPriceLog.setProductId(productID);
							sellingPriceLog.setSalStartTime(start);
							sellingPriceLog.setSalEndTime(end);
							sellingPriceLogDao.save(sellingPriceLog);
							System.out.println(10);
						}
					}
				}
				// 添加促销售价
				if (!StringUtil.isNullStr(sellingPriceProductId)) {
					ContentFee fee = new ContentFee();
					Product product = productService.getByProductId(sellingPriceProductId);
					fee.setPomsId(Long.valueOf(id));
					fee.setType(2);
					fee.setSaleProductId(sellingPriceProductId);
					fee.setPrice(product.getPrice());
					fee.setStartTime(start);
					fee.setEndTime(end);
					fee.setPriceType("1");
					contentFeeDao.save(fee);
					String productName = product.getName();
					String prdPrice = product.getPrice();
					SellingPriceLog sellingPriceLog=new SellingPriceLog();
					SellingPriceLog.putTimeAndUser(sellingPriceLog);
					sellingPriceLog.setName(name);
					sellingPriceLog.setContentId(contentId);
					sellingPriceLog.setPrice(prdPrice);
					sellingPriceLog.setPrdInfoId(id);
					sellingPriceLog.setProductName(productName);
					sellingPriceLog.setProductId(sellingPriceProductId);
					sellingPriceLog.setSalStartTime(start);
					sellingPriceLog.setSalEndTime(end);
					sellingPriceLogDao.save(sellingPriceLog);
					System.out.println(11);
				}
				// 添加权益
				if (!StringUtil.isNullStr(equityIds)) {
					String[] arrayEquityId = equityIds.split(",");
					for (String equityId : arrayEquityId) {
						ContentFee fee = new ContentFee();
						fee.setPomsId(Long.valueOf(id));
						fee.setType(2);
						fee.setEquityId(equityId);
						fee.setStartTime(start);
						fee.setEndTime(end);
						contentFeeDao.save(fee);
						System.out.println(12);
					}
				}
				PrdInfo prdInfo = prdInfoDao.getOne(Long.parseLong(prdInfoId));
				if ((prdInfo.getAutoVomsPublish() == 1 && prdContVo.getPublishNoVOMSStatus() == null)
						|| "22".equals(prdContVo.getPublishNoVOMSStatus()) ) {
					prdContDao.updatePublishNoVOMSStatus(PrdCont.PUBON_STATUS_NOT,prdContVo.getPrdContId());
					System.out.println(13);
				}
			}
		} catch (Exception e) {
			return ResultBean.error(msgConfig.getSaveFail());
		}
		return  ResultBean.ok();
	}

}

